<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8"> 
   <link type="text/css" rel="stylesheet" href="../css/index.css">
    <title>Wintersporttag - Anmeldung</title>
	<script type="text/javascript" src="../java/jquery.min.js" ></script>
	<script type="text/javascript" src="../java/jqFancyTransitions.js"></script>
 </head>
  <body>
    <img src="../bilder/Alber-Schaeffle-Schule.bmp"  alt="Albert-Schäffle-Logo"/> 
      <div class="titel">
		<div id="slideshow">

	<img  src="../java/images/bild1.jpg" alt="" />
<img src="../java/images/bild2.jpg" alt="" />
<img src="../java/images/bild3.jpg" alt=""  />
<img src="../java/images/bild4.jpg" alt=""  />
<img src="../java/images/bild5.jpg" alt=""  />
<img src="../java/images/bild6.jpg"  alt=""  />
</div>
<script type="text/javascript">
$('#slideshow').jqFancyTransitions({ width: 735, height: 139, delay: 2500, effect: 'fade', direction: 'alternate', stripDelay: 80, strips: 20});
</script>
	
	
	
	</div>
	    
	 </div>
	     </div>
	  
	   
	    <div class="inhalt">
<script type="text/javascript">
<!--
function FensterWechsel()
{
parent.location.href="veranstaltung.php";
}
function anmeldung()
{
parent.location.href="index.html";
}
// -->
</script>
</head>
<body>
<?php
session_start();
$nutzer = $_SESSION['username'];
if($nutzer ==NULL)
{
echo "<body onLoad='anmeldung();'>";
}

else
{
$pwneu1 = $_POST['pwNeupasswort'];
$pwneu2 = $_POST['pwNeupasswort2'];
$email  = $_POST['tfEmail'];
$laenge = strlen($pwneu1);

function checkEmailAddress($email)
{
	if(preg_match("/^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})$/", $email))
		return true;
	return false;
}

if($nutzer != NULL AND $pwneu1!= NULL AND $pwneu2 != NULL AND $email != NULL)
{
if ($laenge < 5 )
{
echo "<center>Das Passwort muss aus mindestens 5 Zeichen bestehen";
echo "<br><br><INPUT TYPE=BUTTON VALUE='Zurück' onClick='history.back()'></center>";
}


else
{

if($pwneu1 == $pwneu2)
{

if (!$link = mysql_connect ('localhost', 'dennis', 'dennis'))
{
	echo "Keine Verbindung zu mysql";
}

if (!mysql_select_db('dennis_schuelerdaten', $link))
{
	echo "konnte DB nicht finden";
}
else
{

if(checkEmailAddress($email))
{
$sql="SELECT * FROM schueler WHERE Email ='$email'";
	mysql_query("SET NAMES 'utf8'");

	//SQL-Befehl senden
	$result = mysql_query($sql,$link);
	$row= mysql_fetch_assoc($result);
if ($row!=0)
{
echo"<center>E-Mail wird bereits von einem anderen Nutzer verwendet";
echo"<br><br><INPUT TYPE=BUTTON VALUE='Zurück' onClick='history.back()'></center>";
}

else
{
$sql="UPDATE schueler SET PasswortNeu='$pwneu1', Email='$email' Where Benutzername='$nutzer'";
mysql_query("SET NAMES 'utf8'");
$result = mysql_query($sql,$link);
echo "<body onLoad='FensterWechsel();'>";
echo"</body>";
}
}
else
{
echo "<center>ungültige email";
echo "<br><br><INPUT TYPE=BUTTON VALUE='Zurück' onClick='history.back()'></center>";
}
}
mysql_close($link);
}
else
{
echo "<center>Die Passwörter stimmen nicht überein";
echo "<br><br><INPUT TYPE=BUTTON VALUE='Zurück' onClick='history.back()'></center>";
}
}
}

else
{
echo "<center>Bitte füllen Sie alle Felder aus!";
echo "<br><br><INPUT TYPE=BUTTON VALUE='Zurück' onClick='history.back()'></center>";
}
}
?>
</body>
</html>